package exam.business.service;

import java.util.ArrayList;
import java.util.List;

import exam.common.constant.ResultPort;
import exam.common.key.KeyExamination;
import exam.common.key.KeyQuestion;
import exam.model.dao.TAnswerDAO;
import exam.model.dao.TQuestionDAO;
import exam.model.entity.TAnswerEntity;
import exam.model.entity.TExaminationEntity;
import exam.model.entity.TQuestionEntity;
import exam.system.business.AbstractService;
import exam.system.business.BusinessServiceInfo;
/**
 * <p>ExaminationGetService</p>
 * <p>Xu ly lay thong tin de thi</p>
 * 
 * @author Phong
 * @version (create: 20/5/2012)
 */
public class ExaminationGetService extends AbstractService {
	// tQuestionDAO
	private TQuestionDAO tQuestionDAO = new TQuestionDAO();
	// tAnswerDAO
	private TAnswerDAO tAnswerDAO = new TAnswerDAO();
	@Override
	public String executeService(BusinessServiceInfo serviceInfo)
			throws Exception {
		// yeu cau lay thong tin de thi
		ExaminationGetInfoService examinationGetInfoService = new ExaminationGetInfoService();
		String port = examinationGetInfoService.executeService(serviceInfo);
		if(ResultPort.NONE.equals(port)) {
			return ResultPort.NONE;
		} else {
			// Lay thong tin de thi tu serviceInfo
			TExaminationEntity tExaminationEntity = serviceInfo.getObject(KeyExamination.T_EXAMINATION_ENTITY);
			// yeu cau lay danh sach cau hoi
			List<TQuestionEntity> tQuestionEntityList = tQuestionDAO.select001(tExaminationEntity.getExamId());
			// lay danh sach questionId
			List<Long> questionIdList = new ArrayList<Long>();
			for(int i = 0; i < tQuestionEntityList.size(); i++) {
				questionIdList.add(tQuestionEntityList.get(i).getQuestionId());
			}
			// yeu cau lay danh sach dap an tu questionIdList
			List<TAnswerEntity> tAnswerEntityList = tAnswerDAO.select002(questionIdList);
			// put tQuestionEntityList vao serviceInfo
			serviceInfo.put(KeyQuestion.T_QUESTION_ENTITY_LIST, tQuestionEntityList);
			// put tAnswerEntityList vao serviceInfo
			serviceInfo.put(KeyQuestion.T_ANSWER_ENTITY_LIST, tAnswerEntityList);
			return ResultPort.SUCCESS;
		}
	}
}
